<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>微信消息接收记录</title>
<script type="text/javascript">
	var $grid;
	var editRow = true;
	var selectRow = -1;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/wx/messageReceive/dataGrid",
			fitColumns : true,
			//sortName : "originAppId",
			//sortOrder : "desc",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'app',
				title : '所属公众号',
				sortable : true,
				width : 100,
				formatter : function(value, row, index){
					return value.appName;
				}
			}, {
				field : 'toUserName',
				title : '公众号的微信号',
				sortable : true,
				width : 120
			}, {
				field : 'fromUserName',
				title : '发送方账号',
				sortable : true,
				width : 120
			}, {
				field : 'msgCreateTime',
				title : '消息创建时间',
				sortable : true,
				width : 90
			}, {
				field : 'msgType',
				title : '消息类型',
				sortable : true,
				width : 80
			}, {
				field : 'content',
				title : '内容',
				sortable : true,
				width : 120
			}, {
				field : 'msgId',
				title : '消息',
				sortable : true,
				width : 120
			}, {
				field : 'picUrl',
				title : '图片链接',
				sortable : true,
				width : 120
			}, {
				field : 'mediaId',
				title : '媒体ID',
				sortable : true,
				width : 100
			}, {
				field : 'format',
				title : '语音格式',
				sortable : true,
				width : 100
			}, {
				field : 'thumbMediaId',
				title : '封面素材ID',
				sortable : true,
				width : 120
			}, {
				field : 'locationX',
				title : '地理位置维度',
				sortable : true,
				width : 100
			}, {
				field : 'locationY',
				title : '地理位置经度',
				sortable : true,
				width : 100
			}, {
				field : 'scale',
				title : '地图缩放大小',
				sortable : true,
				width : 100
			}, {
				field : 'label',
				title : '地理位置信息',
				sortable : true,
				width : 100
			}, {
				field : 'title',
				title : '标题',
				sortable : true,
				width : 120
			}, {
				field : 'description',
				title : '描述',
				sortable : true,
				width : 120
			}, {
				field : 'url',
				title : '链接',
				sortable : true,
				width : 120
			}, {
				field : 'recognition',
				title : '语音识别结果',
				sortable : true,
				width : 120
			} ] ],
		}));

		$("#grid").datagrid('enableFilter', [ {
			field : 'isAuth',
			javaType : 'N',
			op : [ 'EQ', 'NEQ', 'GT', 'LT', 'GTE', 'LTE', 'ISNULL', 'NOTNULL' ]
		} ]);

		fn_initComboNotId("appType", "appType", true);//app类型
		fn_initComboNotId("isAuth", "isAuth", true);//默认设置

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});

			$("#dlg").dialog("open").dialog("setTitle", "新增微信公共账号");
		});
		$("#add1").click(function() {
			if (editRow) {
				$grid.datagrid("insertRow", {
					index : 0,
					row : {},
				});
				editRow = false;
			}
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑微信公共账号");
				$("#fm").form("clear");
				$("#fm").form("load", rowData);
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/wx/app/multiDelete");
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
		$("#redo").click(function() {
			$grid.datagrid("rejectChanges");
			editRow = true;
		});

		$("#save").click(function() {
			fn_save();
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/wx/app/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#getUserList").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("请先选中相应应用！");
				return false;
			}
			var url = "${ctx}/wx/wxUser/synUserList";
			$.post(url, {
				appId : rowData.originAppId
			}, function(data) {
				if (data.success) {
					$.messager.show({
						msg : data.msg,
						icon : "info",
						position : "bottomRight"
					});
					//showInfo(data.msg)
				}
			}, "json");
		});
		
		$("#getGroupList").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("请先选中相应应用！");
				return false;
			}
			var url = "${ctx}/wx/groups/synGroupList";
			$.post(url, {
				appId : rowData.originAppId,
				id : rowData.id
			}, function(data) {
				if (data.success) {
					$.messager.show({
						msg : data.msg,
						icon : "info",
						position : "bottomRight"
					});
				}
			}, "json");
		});
	});

	function fn_save() {
		showConfirm("确定保存?保存后所有更改将提交生效", function() {
			$("#grid").datagrid("submitChange", {
				url : "${ctx}/wx/app/crud"
			});
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<span>应用名称：</span> <input type="text" name="search_LIKE_appName"
			style="margin-left: 2px; margin-right: 2px; padding-left: 2px; padding-right: 3px;" />
		<a id="search" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-zoom'">查询</a>
		<shiro:hasPermission name="app:update">
			<a id="add" class="easyui-linkbutton"
				data-options="plain: true, iconCls: 'icon-standard-add'">新增</a>
			<a id="edit" class="easyui-linkbutton"
				data-options="plain: true, iconCls: 'icon-hamburg-pencil'">编辑</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="app:delete">
			<a id="delete" class="easyui-linkbutton"
				data-options="plain: true, iconCls: 'icon-hamburg-busy'">删除</a>
			<div class="dialog-tool-separator"></div>
		</shiro:hasPermission>
		<shiro:hasPermission name="app:export">
			<a id="excelExport" class="easyui-linkbutton"
				data-options="plain: true, iconCls: 'icon-standard-page-excel'">Excel导出</a>
		</shiro:hasPermission>
	
	<shiro:hasPermission name="app:update">
		<div id="dlg" class="easyui-dialog"
			style="width: 600px; height: 300px; padding: 10px 20px"
			data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '保存', iconCls: 'icon-ok', handler: function () { formSave('#fm', '#grid', '#dlg', '${ctx}/wx/messageReceive/update'); } },
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg').dialog('close'); } }
                ],closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>应用ID:</label></td>
						<td><input name="originAppId" class="easyui-validatebox"
							data-options="required: true"></td>
						<td><label>应用名称:</label></td>
						<td><input name="appName" class="easyui-validatebox"
							data-options="required: true"></td>
					</tr>
					<tr>
						<td><label>微信号:</label></td>
						<td><input name="appNo" class="easyui-validatebox"
							data-options="required: true"></td>
						<td><label>账号类型:</label></td>
						<td><input id="appType" name="appType"></td>
					</tr>
					<tr>
						<td><label>介绍:</label></td>
						<td><input name="appDesc" class="easyui-validatebox"
							data-options="required: true"></td>
						<td><label>认证情况:</label></td>
						<td><input id="isAuth" name="isAuth"></td>
					</tr>
					<tr>
						<td><label>地址:</label></td>
						<td><input name="address" class="easyui-validatebox"></td>
						<td><label>登陆邮箱:</label></td>
						<td><input name="loginEmail" class="easyui-validatebox"
							data-options="required: true,validType: 'email'"></td>
					</tr>
					<tr>
						<td><label>应用密钥:</label></td>
						<td><input name="appSecret" class="easyui-validatebox"
							data-options="required: true"></td>
						<td><label>appToken:</label></td>
						<td><input name="appToken" class="easyui-validatebox"
							data-options="required: true"></td>
					</tr>
					<tr>
						<td><label>aesKey:</label></td>
						<td><input name="aesKey" class="easyui-validatebox"></td>
						<td><label>accessToken:</label></td>
						<td><input name="accessToken" class="easyui-validatebox"></td>
					</tr>
					<tr>
						<td><label>expiresIn:</label></td>
						<td><input name="expiresIn" class="easyui-validatebox"></td>
					</tr>
				</table>
			</form>
		</div>
	</shiro:hasPermission>
</body>
</html>
